home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CUJ9206.ARJ / 1006038A < prev    next >
Text File  |  1992-06-02  |  1KB  |  47 lines

  1.  
  2.     #include <ctype.h> 
  3.     #include <stdarg.h> 
  4.     #include <stdio.h> 
  5.     #include <stdlib.h> 
  6.     #include <string.h> 
  7.  
  8.     int rprintf(char *fmt, ...) 
  9.         { 
  10.         va_list args; 
  11.         int len, count; 
  12.         char *r, *f, *c; 
  13.         char rpt_fmt[200]; 
  14.  
  15.         for (r=rpt_fmt, f=fmt; (*r = *f) != '\0'; r++, f++) 
  16.             if (f[0] == '%' && isdigit(f[1])) 
  17.                 if ((c=f+1+strspn(f+1,"0123456789"))[0] == 'r' && c[1] == '(') 
  18.                     { 
  19.                     for (count=atoi(f+1), f=c+2; count != 0; count--) 
  20.                         for (c = f; *c && *c != ')'; *r++ = *c++) 
  21.                             ; 
  22.                     r--; 
  23.                     f = c; 
  24.                     } 
  25.  
  26.         va_start(args, fmt); 
  27.         len = vprintf(rpt_fmt, args); 
  28.         va_end(args); 
  29.  
  30.         return len; 
  31.         } 
  32.  
  33.     void main(void) 
  34.         { 
  35.         rprintf("rprintf output is:\n\n"); 
  36.         rprintf("One=%d, Two=%d.\n", 1, 2); 
  37.         rprintf("Digits=%10r(%d).\n", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); 
  38.         rprintf("Digits=%d%9r(, %d).\n", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); 
  39.         } 
  40.  
  41.     rprintf output is: 
  42.  
  43.     One=1, Two=2. 
  44.     Digits=0123456789. 
  45.     Digits=0, 1, 2, 3, 4, 5, 6, 7, 8, 9. 
  46.  
  47.